
<script>
import { mapActions } from "vuex";
import { listClassify } from "@/apis/app";
import store from "./store";

export default {
  name: "app",
  store,
  onLaunch() {
    this.listClassify();
    this.SET_CURRENT_CLASSIFYS([]);

    // 全局设置暗黑模式
    // #ifdef APP-PLUS
    this.setUIStyle();

    // 持续监听
    uni.onThemeChange(() => {
      
      this.setUIStyle();
    });
    // #endif
  },
  methods: {
    /**
     * 设置当前主题模式
     */
    setUIStyle() {
     
      // let style = plus.navigator.getUiStyle();
      // plus.nativeUI.setUiStyle(style);
      // this.SET_IOS_UI_STYLE(style);

      // console.log(
      //   `当前IOS样式为：${style == "dark" ? "暗黑模式" : "普通模式"}`
      // );
    },

    /*
     * 分类列表
     */
    async listClassify() {
      let { code, data } = await listClassify();
      if (code == 200) {
        data.forEach((item) => {
          if (typeof item._child == "undefined") item._child = [];

          if (item._child.length == 0) {
            item._child.unshift({
              id: item.id,
              pid: item.pid,
              name: item.name,
            });
          }

          item._child.forEach((sitem) => {
            if (typeof sitem._child == "undefined") sitem._child = [];

            sitem._child.unshift({
              id: sitem.id,
              pid: sitem.pid,
              name: "全部",
              title: sitem.name,
            });

            sitem._child.forEach((citem) => {
              if (typeof citem._child == "undefined") citem._child = [];

              citem._child.unshift({
                id: citem.id,
                pid: citem.pid,
                name: "全部",
                title: citem.name,
              });
            });
          });
        });

        this.SET_CLASSIFYS(data);
      }
    },

    ...mapActions([
      "SET_CLASSIFYS",
      "SET_CURRENT_CLASSIFYS",
      "SET_IOS_UI_STYLE",
    ]),
  },
};
</script>

<style lang="scss">
@import "@/common/scss/main.scss";
@import "uview-ui/index.scss";

</style>
